import { h, ref } from 'vue';
import { NAvatar, NImage, NTag, NSwitch, NRate } from 'naive-ui';
import { cloneDeep } from 'lodash-es';
import { FormSchema } from '@/components/Form';
import { Dicts } from '@/api/dict/dict';

import { isArray, isNullObject } from '@/utils/is';
import { getFileExt } from '@/utils/urlUtils';
import { defRangeShortcuts, defShortcuts, formatToDate } from '@/utils/dateUtil';
import { validate } from '@/utils/validateUtil';
import { getOptionLabel, getOptionTag, Option, Options, errorImg } from '@/utils/hotgo';

export class State {
  public id = 0; // id
  public code = ''; // code
  public name = ''; // 名称
  public date = ''; // 日期
  public desc = ''; // 爆发原因
  public strength = null; // 板块强度

  constructor(state?: Partial<State>) {
    if (state) {
      Object.assign(this, state);
    }
  }}

export function newState(state: State | Record<string, any> | null): State {
  if (state !== null) {
    if (state instanceof State) {
      return cloneDeep(state);
    }
    return new State(state);
  }
  return new State();
}



export const rules = {
  code: {
    required: true,
    trigger: ['blur', 'input'],
    type: 'string',
    message: '请输入code',
  },
  date: {
    required: true,
    trigger: ['blur', 'input'],
    type: 'string',
    message: '请输入日期',
  },
};

export const schemas = ref<FormSchema[]>([
  {
    field: 'id',
    component: 'NInputNumber',
    label: 'id',
    componentProps: {
      placeholder: '请输入id',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'code',
    component: 'NInput',
    label: 'code',
    componentProps: {
      placeholder: '请输入code',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'name',
    component: 'NInput',
    label: '名称',
    componentProps: {
      placeholder: '请输入名称',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'date',
    component: 'NDatePicker',
    label: '日期',
    componentProps: {
      type: 'date',
      clearable: true,
      shortcuts: defShortcuts(),
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
]);

export const columns = [
  {
    title: 'id',
    key: 'id',
  },
  {
    title: 'code',
    key: 'code',
  },
  {
    title: '名称',
    key: 'name',
  },
  {
    title: '日期',
    key: 'date',
    render(row) {
      return formatToDate(row.date);
    },
  },
  {
    title: '爆发原因',
    key: 'desc',
  },
  {
    title: '板块强度',
    key: 'strength',
  },
];